<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
    <title>百度地图获取当前位置</title>
    <style>
        .card {
            width: 100%;
            height: 100%;
            border-radius: 5px;
            box-shadow: 0 0 5px 5px #eceaea;
            padding: 10px;
            box-sizing: border-box;
        }

        .locationinfo-title {
            font-weight: bold;
            font-size: 25px;
        }

        .locationinfo-location {
            font-size: 18px;
            font-weight: bold;
        }
    </style>
</head>

<body>
    <div class="location-wrapper">
        <div class="card">
            <div class="locationinfo-title">当前位置</div>
            <div class="locationinfo-location">北京市朝阳区八里庄街道</div>
        </div>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.9.0/vconsole.min.js"></script>
    <script type="text/javascript"
        src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=你的AK"></script>
    <script>
        var vConsole = new VConsole();
    </script>
    <script>
        var oLocation = document.getElementsByClassName('locationinfo-location')[0];
        var geolocation = new BMapGL.Geolocation();
        geolocation.enableSDKLocation();
        geolocation.getCurrentPosition(function (r) {
            let { city, province } = r.address,
                { latitude, longitude } = r;
            oLocation.innerHTML = `省份：${province} 城市：${city} 经${longitude} 纬${latitude} 度`;
        });
    </script>
</body>

</html>